package com.longjianghuasheng.logistics.business.freight.adapter

import android.view.View
import android.widget.ImageView
import androidx.core.view.isGone
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.data.bindadapter.CustomBindAdapter.afterTextChanged
import com.longjianghuasheng.logistics.databinding.ItemDriverCooperationBinding
import com.longjianghuasheng.logistics.entity.CarInfo

class DriverCooperationAdapter :
    BaseQuickAdapter<CarInfo, BaseDataBindingHolder<ItemDriverCooperationBinding>>(R.layout.item_driver_cooperation) {

    var onBooksListener = { view: ImageView, position: Int ->

    }

    override fun convert(
        holder: BaseDataBindingHolder<ItemDriverCooperationBinding>,
        item: CarInfo
    ) {
        holder.dataBinding?.run {

            val onListener = { view: View ->

                onBooksListener.invoke(ivDrivingLicense, holder.absoluteAdapterPosition)
            }

            stvType.centerEditText?.afterTextChanged {

                item.cars_type = it
            }
            stvWeight.centerEditText?.afterTextChanged {
                item.weights = it
            }
            stvLength.centerEditText?.afterTextChanged {
                item.lengths = it
            }
            stvLicensePlate.centerEditText?.afterTextChanged {
                item.license = it
            }

            tvDrivingLicense.setOnClickListener(onListener)
            ivDrivingLicense.setOnClickListener(onListener)
            ivClick.setOnClickListener(onListener)

            tvDelete.isGone = holder.layoutPosition == 0

        }
    }
}